package com.test.burnincash.aaahpoppomelo.view;


import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.test.burnincash.R;
import com.test.burnincash.aaahpoppomelo.bean.OrderItem_hpoppomelo;
import com.test.burnincash.util_burnin.StringUtil_burnin;

public class EditItemView {

    private final View mView;

    private final EditText noEt;
    private final EditText itemNameEt;
    private final EditText priceEt;
    private final EditText quantityEt;

    public EditItemView(View view){
        mView = view;
        noEt = view.findViewById(R.id.view_edit_item_et_no);
        itemNameEt = view.findViewById(R.id.view_edit_item_et_item_name);
        priceEt = view.findViewById(R.id.view_edit_item_et_price);
        quantityEt = view.findViewById(R.id.view_edit_item_et_quantity);
    }

    public View getView() {
        return mView;
    }

    public int getNo() {
        return StringUtil_burnin.safeParseInt(noEt.getText().toString());
    }

    public String getItemName() {
        return StringUtil_burnin.getSafeString(itemNameEt.getText().toString());
    }

    public int getPriceEt() {
        return StringUtil_burnin.safeParseInt(priceEt.getText().toString());
    }

    public int getQuantityEt() {
        return StringUtil_burnin.safeParseInt(quantityEt.getText().toString());
    }

    public OrderItem_hpoppomelo getOrderItem(){

        int no = StringUtil_burnin.safeParseInt(noEt.getText().toString());
        String itemName = StringUtil_burnin.getSafeString(itemNameEt.getText().toString());
        int price = StringUtil_burnin.safeParseInt(priceEt.getText().toString());
        int quantity = StringUtil_burnin.safeParseInt(quantityEt.getText().toString());

        return new OrderItem_hpoppomelo(no,itemName,price,quantity);
    }

    public boolean hasEtEmpty(){
        return TextUtils.isEmpty(noEt.getText())||TextUtils.isEmpty(itemNameEt.getText())||TextUtils.isEmpty(priceEt.getText())||TextUtils.isEmpty(quantityEt.getText());
    }

}
